﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class hydevmanager_admin_menu_manager : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["timeout"]==null)
            {
                Response.Redirect("login.aspx");
            }
            else
            {
                 Load_DataName();
            txtname_menu.Focus();
            Session.Add("fileName", "");
            string str = Session["fileName"].ToString();
            }
           
        }

    }

    protected void luu_click(object sender, EventArgs e)
    {
        try
        {
            int IdParent = Convert.ToInt32(Request.QueryString.Get("IdMenu"));
            int order = DataAccess.ExeStoredGetInt("sp_SelectCounter_MenuOrder_By_IdParent", "@IdParent", IdParent);
            string menu_name = txtname_menu.Text;
            string dataName = drDatatype.SelectedItem.Text;
            string Page_Link = drDatatype.SelectedItem.Value;
            string positions = drposition.SelectedItem.Value;
            string description = txtdescription.Text;
            string picName = "";
            if (Session["fileName"].ToString() != "")
            {
                picName = Session["fileName"].ToString();
            }

            kiemtra_IdParent(IdParent);
            DataAccess.ExeNonStored("sp_InsertInto_dev_Menu", "@idparent", IdParent, "@name_menu", menu_name, "@menu_order", (order + 1), "@positions", positions, "@data_name", dataName, "@link_page", Page_Link, "@picture", picName);

            //Response.Redirect(Request.ServerVariables["HTTP_REFERER"]);
            Response.Redirect("admin_manager_menu.aspx");
        }
        catch { }
    }

    protected void kiemtra_IdParent(int IdParent)
    {
        if (IdParent != 0)
        {
            DataAccess.ExeNonStored("sp_UpDate_HasChild_dev_Menu", "@IdParent", IdParent);
        }
    }

    protected void Load_DataName()
    {
        drDatatype.DataTextField = "data_name";
        drDatatype.DataValueField = "link_page";
        drDatatype.DataSource = DataAccess.ExeStoredToDataTable("sp_SelectAll_dev_DataType_Link");
        drDatatype.DataBind();
        drDatatype.Items.Insert(0, "--- Chọn Page Link ---");
    }
}
